<?php
/*******************************************************************************
login.php

Created by Maurice York (maurice_york@ncsu.edu)
Modified by NCSU Libraries, NC State University. Modifications by Karl Doerr (libraries.opensource@ncsu.edu).

This file is part of NCSU's distribution of ReservesDirect. This version has not been downloaded from Emory University
or the original developers of ReservesDirect. Neither Emory University nor the original developers of ReservesDirect have authorized
or otherwise endorsed or approved this distribution of the software.

Copyright (c) 2004-2006 Emory University, Atlanta, Georgia.

Licensed under the NCSU ReservesDirect License, Version 2.0 (the "License"); 
you may not use this file except in compliance with the License.You may obtain a copy of the full License at
 http://www.lib.ncsu.edu/it/opensource/

ReservesDirect is distributed in the hope that it will be useful,
but is distributed "AS IS" and WITHOUT ANY WARRANTY, without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE, and without any warranty as to non-infringement of any third
party's rights.See the License for the specific language governingpermissions and limitations under the License.

The original version of ReservesDirect is located at:
http://www.reservesdirect.org/

This version of ReservesDirect, distributed by NCSU, is located at:
http://code.google.com/p/reservesdirect-ncsu/

*******************************************************************************/
$debugMode = true;
$errorLevel = E_ALL; //0 for none or E_ALL for all

if($debugMode){
	error_reporting($errorLevel);
	ini_set('display_errors', 'On');
}

if(!($_REQUEST["mobile"] == "true")){
	require_once('Curl_Tunnel.php');

	//Create a Tunnel for includes
	$curlTunnel = new Curl_Tunnel('http://www.lib.ncsu.edu/', 
	array(
		'useCache' => true,
		'cacheShelfLife' => 60,
		'cacheTarget' => '/tmp/',
		'translatePaths' => false
	)
);
	
}


$mobile = false;

// Detect mobile device. If mobile (or if "mobile=true" is included in URL query string), sets $mobile to true.
// Variable is passed into login form to be available to next screen
if ($_SERVER['HTTP_USER_AGENT'] && !($_REQUEST["mobile"] == "true")) {	  
	$url = 'http://webapps.ncsu.edu/wurfl/?method=getDeviceByUserAgent&userAgent=' . urlencode($_SERVER['HTTP_USER_AGENT']) . '&capabilities=mobile_browser,model_name,device_os';

	//$result = @file_get_contents($url);

	// Initialize the CURL library
	$ch = curl_init();

	// Set the URL to execute
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_TIMEOUT, 180);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_USERAGENT, "NCSU Libraries Reserves Direct Mobile");

	// Set options

	// Execute, saving results in a variable
	$result = curl_exec($ch);

	// Close CURL resource
	curl_close($ch);

//	if ($result !== false) {
//		$res = simplexml_load_string($result);
//
//		/*echo "<pre>";
//		print_r($res);
//		die();
//		 */
//		if ($res->getDeviceByUserAgent->id == 'generic_web_crawler') {
//			$type = 'spider';
//		} elseif ((string)$res->getDeviceByUserAgent->capabilities->mobile_browser == '') {
//			$type = 'computer';
//		} elseif (preg_match('/.*?(Palm|SymbianOS|Windows CE|BlackBerry)/i', $res->getDeviceByUserAgent->userAgent)) {
//			$type = 'smart_phone';
//		} elseif (preg_match('/.*?(iPhone|iPod|Aspen Simulator|Android|webOS)/i', $res->getDeviceByUserAgent->userAgent)) {
//			$type = 'iphone';
//		}
//	}
	if ((isset($type) && ($type == 'smart_phone' || $type == 'iphone')) || $_REQUEST["mobile"] == "true") {
		$mobile = true;
	}
	else {
		$mobile = false;
	}
}

if($_REQUEST["mobile"] == "true"){
	$mobile = true;
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<!-- METADATA: insert content from stage/webpub/metadata form below this line -->
<title>Course Reserves - Login</title>
<meta name="DC.Title" content="My Course Reserves Project" />
<meta name="DC.Creator" content="Hurteau, Troy" />
<meta name="DC.Subject" scheme="Local" content="My Courses" />
<meta name="DC.Publisher" content="North Carolina State University. Libraries." />
<meta name="DC.Date" content="2008-08-15" />
<meta name="DC.Language" content="en" />
<meta name="DC.Rights" content="North Carolina State University" />
<?php if ($mobile): ?>
	<meta name="viewport" content="width=device-width, user-scalable=no">
<?php endif;?>

<!-- HEAD: do not remove -->
<?php if ($mobile): ?>
	<link rel="stylesheet" href="css/mobile.css" type="text/css">
<?php else: ?>
	<?php $curlTunnel->cPrint("/website/includes/head.html"); ?>
<?php endif;?>


<script language="JavaScript1.2" src="secure/javascript/jsFunctions.js"></script>
</head>
<body <?=($mobile?"id='mobileBody'" : "")?> onload="var elmt = document.getElementById('user_name'); if(elmt) { elmt.focus(); } else { focusOnForm(); }">

<?php if ($mobile):?>
	<?php include("secure/html/bannerM.inc.html"); ?>
<?php else: ?>
	<!-- BANNER: do not remove -->
	<?php $curlTunnel->setTranslatePathMode('links')->cPrint("/website/includes/header.html"); ?>

<?php endif; ?>

<table <?=($mobile?"style='padding-top: 35px;'":'width="100%"')?> border="0" align="center" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td id="mainContent" style="padding: 0px;">

      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr valign="top">
          <td id="mainContentTextServices" style="padding: 0px;">

<!-- TITLE OF PAGE: enter title of page -->
<h1 class="loginTitle">Course Reserves</h1>
<!-- BEGIN CONTENT -->

<table>
  <tr>
    <td align="left" width="40%">
	
	  <span class="loginTitle" style="padding-bottom:5px;"><font <?=($mobile?"":'face="verdana, arial, helvetica, sans-serif"')?> size=4><b>NC State Login Required</b></font><br/></span>
	  <font <?=($mobile?"":'face="verdana, arial, helvetica, sans-serif"')?> size=2 class="loginTitle"><i>Please enter your Unity ID and password</i></font><br /> 

   
	<table width="100%">
	  <tr>
	    <td align="center">
	
	      <font <?=($mobile?"":'face="verdana, arial, helvetica, sans-serif"')?> size=2 class="login">
	  	    
      
	        <form name="RDlogin" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>" style="margin:0px;">
                <table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="loginBox" height="44">
                  <tr valign="top">
                    <td width="11%" height="10">&nbsp; </td>
                    <td width="75%">
                      <div id="loginText">
					  <?php if(isset($login_error) && $login_error): ?>
					  	<font color="red">Invalid username or password</font>
					  <?php endif; ?>
					  <p><strong>Username:</strong>
                          <input name="username" id="user_name" type="text" size="15" autocapitalize="off" autocorrect="off" class="loginInput"></p> 
                          
                          <p><strong>Password:&nbsp;
                          <input name="pwd" type="password" size="15" class="loginInput">
                        </strong> </p></div>
                    </td>
                    <td width="14%">&nbsp;</td>
                  </tr>
                  <tr valign="top">
                    <td height="34" colspan="3" align="center">
	                  <input type="hidden" name="mobile" value="<?=($mobile?"true":"false")?>" />
                      <input name="submitForm" type="submit" value="Sign In" style="width:8em; height:3em;">
                    </td>
                  </tr>
                </table>
                </form>
  		  </font>
		  <?php if ($mobile): ?>
			<div class="mobileNote">
				Content may not be viewable on all devices.
			</div>
		  <?php else: ?>
		  <br />
		  	<div class="mobileNote">
		  		Course Reserves Mobile
		  	</div>
		  	<div class="mobileNote">
				<a href="index.php?mobile=true">Log in here</a>
			</div>
		  <?php endif; ?>		
        </td>

      </tr>
    </table>  			
  			
  	  
	 <!--  <br clear="all"/>  --> 
	 <br/>
	</td>
  </tr>
</table>

<!-- END OF CONTENT -->

          </div></td>
        </tr>
      </table>
    </td>
    <td class="shadowRight"><img src="/website/images/clear.gif" width="3" height="1" alt=" " /></td>
  </tr>
  <tr>
    <td class="shadowBottom"><img src="/website/images/clear.gif" width="1" height="4" alt=" " /></td>
    <td><img src="/website/images/clear.gif" width="1" height="4" alt=" " /></td>
  </tr>
</table>

<?php if (!$mobile): ?>
	<!-- FOOTER: do not remove -->
	<?php $curlTunnel->cPrint("/website/includes/footer.html"); ?>
<?php endif;?>

<?php if ($mobile):?>
	<?php include("secure/html/footerM.inc.html"); ?>
<?php endif; ?>
</body>
</html>

  